# Contributor: Edward E. <develinthedetail@gmail.com>

_realname=libheif
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.0
pkgrel=1
pkgdesc="HEIF image decoder/encoder library and tools (mingw-w64)"
arch=('any')
url="https://github.com/strukturag/libheif"
license=('LGPL3' 'MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libde265"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-aom"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git"
         "${MINGW_PACKAGE_PREFIX}-x265")
options=('strip')
source=("https://github.com/strukturag/libheif/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-fix-pkgconfig-provide-includedir.patch
        initialize-img_format-and-fix-warnings.patch)
sha256sums=('e43ef91a5ad41de4471a2fd484279d0793b419009a7d102965739da8f7b75d96'
            'b782444a8f2c3f23c3b57e6e0a25ebe1313656aeeb72fad2335b1c6ee4b90a0b'
            'f923553318fce9c1fe0abb5e054cb92c63ffa19b116e8e33d8b60dffd87fdcea')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-pkgconfig-provide-includedir.patch

  # already fixed upstream for next release
  patch -Np1 -i ${srcdir}/initialize-img_format-and-fix-warnings.patch
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --disable-gdk-pixbuf \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-go

  make
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
